<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件代理</title>
</head>
<body>
  <ul>

  </ul>
</body>
<script>
  ;(function(doc){
    var oUl = doc.getElementsByTagName("ul")[0];
    var ofrag = doc.createDocumentFragment();
    // console.log(oUl);
    for(var i = 0; i < 10; i++){
      var oLi = doc.createElement("li");
      oLi.innerText = "列表第" + (i + 1) + "项";
      // (function(i){
      //   oLi.onclick = function(){
      //     console.log(this.innerText);
      //     console.log(i);
      //   }
      // })(i)
      ofrag.appendChild(oLi);
    }
    oUl.appendChild(ofrag);

    oUl.addEventListener('click', function(e){
      var e = e || window.event,
          target = e.target,
          tarName = target.tagName.toLowerCase();
      
      if(tarName === "li"){
        console.log(target.innerText);
      }
    }, false);

  })(document)


  var str = "1000";

  function reverseString(str){
    return str.split('').reverse().join('');
  }
  console.log(reverseString(str));


  ;(function(){
    function Stack(){
      this.data = [];
      this.index = [];
    }

    Stack.prototype.push = function(element){
      this.data[this.index++] = element;
    }

    Stack.prototype.pop = function(){
      return this.data[--this.index];
    }

    Stack.prototype.length = function(){
      return this.length;
    }

    Stack.prototype.cout = function(){
      console.log(this.data);
    }

    window.Stack = Stack;
  })();

  console.log(stack);
  var stack = new Stack();

  stack.push(3);
  stack.cout();
</script>
</html>